﻿using System.Collections.Generic;
using System.Runtime.Serialization;

namespace ClientOverflow.DataTransferObjects
{
    /// <summary>
    /// Answer class is a DTO representing the answer in the server side. The answer class contains
    /// information about the class, such as the question votes.
    /// The class is decorated with [DataContract] attribute and the properties are decorated with
    /// [DataMember] attributes. Using the decorations the class is compatible as data trasnfer object
    /// in the WCF service.
    /// </summary>
    [DataContract]
    public class Answer
    {
        [DataMember]
        public int ID { get; set; }

        [DataMember]
        public string Content { get; set; }

        public Question Question { get; set; }

        [DataMember]
        public List<Vote> UpVotes { get; set; }

        [DataMember]
        public List<Vote> DownVotes { get; set; }

        public bool Equals(Answer other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.ID == ID;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (Answer)) return false;
            return Equals((Answer) obj);
        }

        public override int GetHashCode()
        {
            return ID;
        }
    }
}